<template>
	<view class="out">
		<!-- 首页线上预约区域 -->
		<view class="home-reservation">
			<!-- 日期选择区域 -->
			<u-scroll-list :indicator="false">
				<view v-for="(item, index) in weekList" :key="index">
					<view class="date-box" :class="dataIndex === index ? 'active' : ''"  @click="chooseWeek(index)">
						<text>{{item.dateTime}}</text>
						<text>{{item.weekName}}</text>
					</view>
				</view>
			</u-scroll-list>
			<!-- 列表区域 -->
			<view class="reservation-list">
				
				<view  v-show="doctorList.length==0">
					<u-empty mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png" text="暂无医生排班">
					</u-empty>
				</view>
				
				<view class="list-box" v-for="item in doctorList" :key="item.id" v-show="doctorList.length>0">
					<u-avatar size="50" src="../static/image/doctor.jpg" @click="toDetail(item.id)"></u-avatar>
					<view class="list-count">
						<text class="title" style="color: #000;">{{item.realName}} <text class="title" style="margin-left: 15rpx;">{{item.occupationTitle}}</text></text>
						<text class="title" style="color: #000;">{{item.hospital}} | {{item.administrativeOffice}}</text>
						<u--text :lines="2" size="22rpx"
							:text="'擅长:'+item.personalExpertise"></u--text>
					</view>
					<view class="list-btn">
						<text class="money">¥{{item.consultExpense==0.00?'免费':item.consultExpense}}</text>
						<u-button type="success" size="mini" shape="circle" color="#54b6ab" @click="toNav(item.id)">立即预约</u-button>
					</view>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				dataIndex: 0,
				weekList: [],
				doctorList: []
			};
		},
		onLoad(option) {
			if (option.type == 0) {
				uni.setNavigationBarTitle({
					title: '普通门诊'
				})
				this.findCurrentWeekDoctorList(1)
			} else {
				uni.setNavigationBarTitle({
					title: '专家门诊'
				})
				this.findCurrentWeekDoctorList(2)
			}

		},
		methods: {
			//跳转医生详情页
			toDetail(doctorId){
				uni.navigateTo({
					url:'/pages/doctorDetails?doctorId='+doctorId
				})
			},
			//立即预约
			toNav(doctorId){
				uni.navigateTo({
					url:'/pages/doctorDetails?doctorId='+doctorId
				})
			},
			//切换星期
			chooseWeek(index) {
				this.dataIndex = index
				this.doctorList = this.weekList[this.dataIndex].doctorList
			},
			//查询当前星期医生排班
			async findCurrentWeekDoctorList(physicianRank) {
				const {
					data
				} = await uni.$http.post('/patient-doctor/findCurrentWeekDoctorList?physicianRank=' + physicianRank)
				if (data.code === 200) {
					this.weekList = data.data
					this.doctorList = this.weekList[this.dataIndex].doctorList
				}
			},
		}
	}
</script>

<style lang="scss">
	.out {
		width: 100%;
		height: 100%;
		background-color: #f2f2f2;
		overflow: auto;

		.home-reservation {
			margin: 20rpx auto;
			width: 95%;
			background-color: #fff;
			border-radius: 20rpx;
			padding: 20rpx;
			box-sizing: border-box;

			.date-box {
				width: 150rpx;
				height: 80rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
			}

			.active {
				color: #54b6ab;
			}

			.reservation-list {
				width: 100%;

				.list-box {
					width: 100%;
					padding: 20rpx;
					box-sizing: border-box;
					border-bottom: 2rpx solid #999;
					display: flex;
					align-items: stretch;
					justify-content: space-between;

					image {
						width: 100rpx;
						height: 100rpx;
					}

					.list-count {
						width: calc(100% - 300rpx);
						display: flex;
						flex-direction: column;

						.title {
							font-size: 26rpx;
							color: #999;
							margin-bottom: 20rpx;
							box-sizing: border-box;
						}

						.count {
							word-break: break-all;
							text-overflow: ellipsis;
							display: -webkit-box;
							-webkit-box-orient: vertical;
							-webkit-line-clamp: 2;
							overflow: hidden;
							font-size: 20rpx;
						}
					}

					.list-btn {
						width: 140rpx;
						display: flex;
						flex-direction: column;
						align-items: flex-end;
						justify-content: space-around;

						.money {
							color: red;
							font-weight: bold;
							font-size: 26rpx;
						}
					}
				}
			}
		}


	}
</style>